-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-82 TransportContext: merge and key iterator #85
Conversation
It's take me few minutes to get how "merge with override" works. 🤔 That's surprising me but if it works why not. I guess one drawback is that merged context takes probably a bit more memory than necessary. I didn't test it but reading the code I guess that : TransportContext ctx1 = TransportContext.of(DUMMY_KEY, "111").with(DUMMY_KEY2, "222");
TransportContext ctx2 = TransportContext.of(DUMMY_KEY, "aaa");
TransportContext ctx1Ctx2 = ctx1.with(ctx2);
TransportContext ctx3 = TransportContext.of(DUMMY_KEY, "aaa").with(DUMMY_KEY2, "222");
// OR TransportContext ctx3 = TransportContext.of(DUMMY_KEY2, "222").with(DUMMY_KEY, "aaa");
// not sure about the merge order : this makes me think
// that maybe a better name would be addFirst() or addLast() (instead of with())
// Just because order seems relevant for equals()
assertEquals(ctx1Ctx2, ctx3);
// From user point of view, I guess this should be equal, but is it ?
// reading the code I'm not sure. and also if I iterate over (I maybe totally missed something, sorry I didn't take time to execute code) |
Yes, that is correct. |
8169ac0
to
fb56170
Compare
@sbernard31 Now that it is fixed by returning Set with keys. |
I looked at this. But not the "equals" one ? See code comment in code block of #85 (comment). |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #85 +/- ##
============================================
+ Coverage 93.11% 93.15% +0.03%
- Complexity 1992 1998 +6
============================================
Files 132 132
Lines 4505 4513 +8
Branches 616 616
============================================
+ Hits 4195 4204 +9
Misses 168 168
+ Partials 142 141 -1 ☔ View full report in Codecov by Sentry. |
Well, that is true, equals will not be true. |
(let me know if I should review this again ?) |
Yes, please ;) |
@@ -66,6 +68,17 @@ public <T> TransportContext with(Key<T> key, T value) { | |||
return new TransportContext(requireNonNull(key), requireNonNull(value), this); | |||
} | |||
|
|||
public TransportContext with(TransportContext otherCtx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add some javadoc to explain that :
If a key exists in both contexts, the otherCtx
value will be used.
I'm still a bit confused by the idea that a not used key/value pair should still be stored in memory 😅 (#85 (comment))
But alternative will probably lead to more costly(and complex) way to merge 2 So this looks good to me. |
Purpose for |
No description provided.